import { getHotSongers, getLetterArtists } from '../api/index'
import Network from '../api/network'
export const getRandom = (min, max) => {
  min = Math.ceil(min)
  max = Math.floor(max)
  return Math.floor(Math.random() * (max - min + 1)) + min
}
export const formartTime = (time) => {
  const differSecond = time
  let day = Math.floor(differSecond / (60 * 60 * 24))
  day = day >= 10 ? day : '0' + day
  let hour = Math.floor(differSecond / (60 * 60) % 24)
  hour = hour >= 10 ? hour : '0' + hour
  let minite = Math.floor(differSecond / 60 % 60)
  minite = minite >= 10 ? minite : '0' + minite
  let second = Math.floor(differSecond % 60)
  second = second >= 10 ? second : '0' + second
  return {
    day: day,
    hour: hour,
    minite: minite,
    second: second
  }
}
export const getAllArtists = () => {
  return new Promise(function (resolve, reject) {
    const list = [getHotSongers()]
    const keys = ['热']
    for (let i = 65; i <= 90; i++) {
      const char = String.fromCharCode(i)
      keys.push(char)
      list.push(getLetterArtists(char))
    }
    Network.all(list)
      .then(function (result) {
        const obj = {}
        obj.keys = keys
        obj.list = result
        resolve(obj)
      })
      .catch(function (err) {
        reject(err)
      })
  })
}
